#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string str;
    int n = 0;
    cin >> str >> n;
    while (n--)
    {
        int a, b;
        string s1, s2, jianqie;
        cin >> a >> b >> s1 >> s2;
        jianqie = str.substr(a - 1, b - a + 1);
        str.erase(a - 1, b - a + 1);
        size_t found = str.find(s1 + s2);
        if (found == str.npos) str += jianqie;
        else str.insert(found + s1.size(), jianqie);
    }
    cout << str << endl;
    return 0;
}